package pers.cz.controller;

import pers.cz.model.Menu;
import pers.cz.service.QueryMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: PostGirl-panent
 * @description: QueryMenuController
 * @author: Cheng Zhi
 * @create: 2021-04-06 10:30
 **/
@RestController
@RequestMapping(path = "/api/queryMenu")
@Api(tags = "获取菜单接口")
public class QueryMenuController {

    @Autowired
    QueryMenuService queryMenuService;

    @GetMapping(path = "/getAllMenuByUserId")
    @ApiOperation(value = "根据用户Id获取该用户菜单")
    public List<Menu> getAllMenuByUserId() {

        Integer userId = Integer.valueOf(SecurityContextHolder.getContext().getAuthentication().getPrincipal().toString());
        List<Menu> menus = queryMenuService.getAllMenuByUserId(userId);
        return menus;
        //return RespBean.ok("获取菜单成功",menus);
    }
}
